package com.ars.common.dao.activity;

import com.ars.common.beans.Active.Active;
import com.ars.common.utils.DBUtil;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * ClassName: FindActivityById
 * Package: com.ars.common.dao.activity
 * Description:
 *
 * @Author: Bryan Long
 * @Create: 2024/7/30 - 8:50
 * @Version: v1.0
 */
public class FindActivityById {
    public static Active findActivityById(String id) throws SQLException, ClassNotFoundException {
        String sql = "-- 左连接查询\n" +
                "SELECT a.id, a.name,a.creatorID, a.beginTime, a.endTime, a.type\n" +
                "FROM active a\n" +
                "where a.id = ?" ;

        PreparedStatement ps = DBUtil.getConnection().prepareStatement(sql);

        int ID = Integer.parseInt(id);
        ps.setString(1, String.valueOf(ID));

        ResultSet rs = ps.executeQuery();

        Active active = new Active();

        while(rs.next()) {
            active.setId(rs.getInt("id"));
            active.setName(rs.getString("name"));
            active.setCreatorID(rs.getString("creatorID"));
            active.setBeginTime(rs.getString("beginTime"));
            active.setEndTime(rs.getString("endTime"));
            active.setType(rs.getString("type"));
        }

        return active;

    }
}
